#ifndef DORMITORYMANAGE_H
#define DORMITORYMANAGE_H

#include <QWidget>
#include <QTableWidget>
#include <QComboBox>
#include <QLineEdit>
#include <QPushButton>
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGroupBox>
#include <QMessageBox>
#include <QHeaderView>

class MainWindow;
class Database;

class DormitoryManage : public QWidget
{
    Q_OBJECT

public:
    explicit DormitoryManage(MainWindow *parent = nullptr);
    ~DormitoryManage();

    void refreshData();

private slots:
    void onUnitSelected(const QString &unit);
    void onAddUnitClicked();
    void onDeleteUnitClicked();
    void onAddRoomClicked();
    void onDeleteRoomClicked();
    void onEditRoomClicked();
    void onRoomTableItemClicked(int row, int column);

private:
    MainWindow *mainWindow;
    Database *database;

    // 单元管理
    QComboBox *unitComboBox;
    QLineEdit *unitNameEdit;
    QPushButton *addUnitButton;
    QPushButton *deleteUnitButton;

    // 房间管理
    QTableWidget *roomsTable;
    QLineEdit *roomNumberEdit;
    QPushButton *addRoomButton;
    QPushButton *deleteRoomButton;
    QPushButton *editRoomButton;

    QString currentUnit;
    QString currentRoom;
    QString originalRoomNumber;
    bool isEditMode;

    void setupUi();
    void loadUnits();
    void loadRooms();
};

#endif // DORMITORYMANAGE_H